001 package net.sf.xdc.util;
002
003 /*
004 * Copyright 2005-2006 Jens Voß.
005 *
006 * Licensed under the GNU Lesser General Public License (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://opensource.org/licenses/lgpl-license.php
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 import java.io.IOException;
020 import java.io.Writer;
021 import javax.xml.transform.Result;
022
023 import org.apache.xml.serialize.HTMLSerializer;
024 import org.apache.xml.serialize.OutputFormat;
025
026 /**
027 * This class is used to serialize an HTML document to a stream. In addition to
028 * the standard HTML serializer provided by the JDK, it supports
029 * "disable-output-escaping" sections.
030 *
031 * @author Jens Voß
032 * @since 0.5
033 * @version 0.5
034 */
035 public class XdcSerializer extends HTMLSerializer {
036
037 private boolean lastSpacePreservation;
038
039 /**
040 * Public constructor.
041 *
042 * @param writer The <code>Writer</code> to which the tree is serialized
043 * @param outputFormat An <code>OutputForma</code> object controlling
044 * various output options
045 */
046 public XdcSerializer(Writer writer, OutputFormat outputFormat) {
047 super(writer, outputFormat);
048 }
049
050 /**
051 * This method adds support for the "disable-output-escaping" processing
052 * instruction.
053 *
054 * @param string The name of the processing instruction
055 * @param string1 The code used for this processing instruction
056 * @throws IOException
057 */
058 public void processingInstructionIO(String string, String string1)
059 throws IOException {
060 if (Result.PI_DISABLE_OUTPUT_ESCAPING.equals(string)) {
061 lastSpacePreservation = this.getElementState().preserveSpace;
062 this.startNonEscaping();
063 this.getElementState().preserveSpace = true;
064 }
065 else if (Result.PI_ENABLE_OUTPUT_ESCAPING.equals(string)) {
066 this.endNonEscaping();
067 this.getElementState().preserveSpace = lastSpacePreservation;
068 }
069 else {
070 super.processingInstructionIO(string, string1);
071 }
072 }
073
074 }